<?php

namespace app\merchant\service;

use app\common\lib\Api;
use think\Db;
use app\merchant\model\TpMerchant;
use app\merchant\model\MerchantConfig;
use app\merchant\model\User;
use yii\base\Object;


/**
 * 商户基础信息
 */
class MerchantService
{
    /**
     * 获取单个商户信息
     * @param $user_id int 商户user_id
     * @return array
     */
    public static function show($user_id)
    {
        //用户信息
        $user = User::where('uid', '=', $user_id)->where('status', '=', 1)->where('m_type', '=', 3)->find();
        if(!$user){
            return [];
        }
        //商户信息
        $merchant['info'] = TpMerchant::where('user_id', '=', $user_id)->find()->toArray();
        $merchant['info']['bond'] = number_format($merchant['bond'], 2);
        //商户配置
        $merchant['arr_MerchantConfig'] = MerchantConfig::where('user_id', '=', $user_id)->where('status', '=', 1)->select()->toArray();

        return $merchant;
    }






    /**
     * 商户某天应还金额
     * @param integer $user_id
     * @param string $day
     * @return string
     */
    public static function repayment_day($user_id,$day)
    {
        $data = [
            'user_id' => $user_id,
            'settle_date'=>$day
        ];
        $result =  Api::doRequest(Api::GET_REPAY_MONEY_BY_DAY,Api::GET,$data);
        if($result['code'] == 0){
            return  $result['data']['total'];
        }
        else{
            throw new \Exception('获取商户还款数据失败');
        }

    }

    /**
     * 
     * @param string $image 图片路径
     * @param integer $user_id 用户Id
     * @return Object

    public function image_update($image, $user_id)
    {
        $Object = new Loginsercive();
        $Reply = $Object->Material_uploading($image, $user_id);
        return $Reply;
    }*/

}
